﻿var request = require('request');
var crypto = require("crypto");
var qs = require('querystring');
var log = require('./logger.js');
var config = require('../config.js');

var tools = {
    md5: function (str) {
        var crypto_md5 = crypto.createHash('md5');
        crypto_md5.update(str, 'utf8'); // 加入编码
        return crypto_md5.digest('hex');
    },
    search: function (ShipperCode, LogisticCode, phone = "") {

        console.log("sss");
        var _this = this;
        return new Promise((resolve, reject) => {

            request({
                url: 'https://ali-deliver.showapi.com/showapi_expInfo?com=' + ShipperCode + '&nu=' + LogisticCode + "&phone=" + phone,
                method: "GET",
                headers: {
                    "content-type": "application/x-www-form-urlencoded",
                    "Authorization": "APPCODE " + "707f7bdc77d6444ba0ba45d5bbd37a1f",

                }
            }, function (error, response, body) {

                // console.log("ss", error, body);
                if (!error && response.statusCode == 200) {
                    //    console.log(JSON.parse(body)) // 请求成功的处理逻辑
                    var json = JSON.parse(body);
                    console.log("f", json.showapi_res_code);
                    if (json.showapi_res_code == "0") {
                        console.log("cc", json.showapi_res_body.data);
                        resolve(json.showapi_res_body);
                    } else {
                        resolve(null);
                    }

                } else {
                    resolve(null);
                }
            });



        })

    }

}


//tools.search("shunfeng", 322884785054);


module.exports = tools;